using System;
using System.Data;
using System.Data.SqlTypes;
using System.Data.SqlClient;

namespace DataEntity
{
	public class T_Project_SalseAgency : DBInteractionBase
	{
		#region Class Member Declarations
            private SqlInt32        _project_SalseAgency_TypeID;
			private SqlString		_project_SalseAgency_FirstA3, _project_SalseAgency_FirstB1, _project_SalseAgency_FirstB2, _project_SalseAgency_FirstA2, _project_SalseAgency_FirstA1;
			private SqlGuid			_project_SalseAgency_ID, _project_SalseAgency_MainID;
		#endregion




		


		public override bool Update()
		{
			SqlCommand	cmdToExecute = new SqlCommand();
			cmdToExecute.CommandText = "dbo.[sp_t_Project_SalseAgency_Update]";
			cmdToExecute.CommandType = CommandType.StoredProcedure;

			// Use base class' connection object
			cmdToExecute.Connection = _mainConnection;

			try
			{
				cmdToExecute.Parameters.Add(new SqlParameter("@guidProject_SalseAgency_ID", SqlDbType.UniqueIdentifier, 16, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _project_SalseAgency_ID));
				cmdToExecute.Parameters.Add(new SqlParameter("@guidProject_SalseAgency_MainID", SqlDbType.UniqueIdentifier, 16, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _project_SalseAgency_MainID));
				cmdToExecute.Parameters.Add(new SqlParameter("@sProject_SalseAgency_FirstA1", SqlDbType.NVarChar, 20, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _project_SalseAgency_FirstA1));
				cmdToExecute.Parameters.Add(new SqlParameter("@sProject_SalseAgency_FirstA2", SqlDbType.NVarChar, 20, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _project_SalseAgency_FirstA2));
				cmdToExecute.Parameters.Add(new SqlParameter("@sProject_SalseAgency_FirstA3", SqlDbType.NVarChar, 20, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _project_SalseAgency_FirstA3));
				cmdToExecute.Parameters.Add(new SqlParameter("@sProject_SalseAgency_FirstB1", SqlDbType.NVarChar, 20, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _project_SalseAgency_FirstB1));
				cmdToExecute.Parameters.Add(new SqlParameter("@sProject_SalseAgency_FirstB2", SqlDbType.NVarChar, 20, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _project_SalseAgency_FirstB2));

				if(_mainConnectionIsCreatedLocal)
				{
					// Open connection.
					_mainConnection.Open();
				}
				else
				{
					if(_mainConnectionProvider.IsTransactionPending)
					{
						cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
					}
				}

				// Execute query.
				_rowsAffected = cmdToExecute.ExecuteNonQuery();
				return true;
			}
			catch(Exception ex)
			{
				// some error occured. Bubble it to caller and encapsulate Exception object
				throw new Exception("T_Project_SalseAgency::Update::Error occured.", ex);
			}
			finally
			{
				if(_mainConnectionIsCreatedLocal)
				{
					// Close connection.
					_mainConnection.Close();
				}
				cmdToExecute.Dispose();
			}
		}


		public override bool Delete()
		{
			SqlCommand	cmdToExecute = new SqlCommand();
			cmdToExecute.CommandText = "dbo.[sp_t_Project_SalseAgency_Delete]";
			cmdToExecute.CommandType = CommandType.StoredProcedure;

			// Use base class' connection object
			cmdToExecute.Connection = _mainConnection;

			try
			{
				cmdToExecute.Parameters.Add(new SqlParameter("@guidProject_SalseAgency_ID", SqlDbType.UniqueIdentifier, 16, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _project_SalseAgency_ID));

				if(_mainConnectionIsCreatedLocal)
				{
					// Open connection.
					_mainConnection.Open();
				}
				else
				{
					if(_mainConnectionProvider.IsTransactionPending)
					{
						cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
					}
				}

				// Execute query.
				_rowsAffected = cmdToExecute.ExecuteNonQuery();
				return true;
			}
			catch(Exception ex)
			{
				// some error occured. Bubble it to caller and encapsulate Exception object
				throw new Exception("T_Project_SalseAgency::Delete::Error occured.", ex);
			}
			finally
			{
				if(_mainConnectionIsCreatedLocal)
				{
					// Close connection.
					_mainConnection.Close();
				}
				cmdToExecute.Dispose();
			}
		}





		public override DataTable SelectAll()
		{
			SqlCommand	cmdToExecute = new SqlCommand();
			cmdToExecute.CommandText = "dbo.[sp_t_Project_SalseAgency_SelectAll]";
			cmdToExecute.CommandType = CommandType.StoredProcedure;
			DataTable toReturn = new DataTable("t_Project_SalseAgency");
			SqlDataAdapter adapter = new SqlDataAdapter(cmdToExecute);

			// Use base class' connection object
			cmdToExecute.Connection = _mainConnection;

			try
			{

				if(_mainConnectionIsCreatedLocal)
				{
					// Open connection.
					_mainConnection.Open();
				}
				else
				{
					if(_mainConnectionProvider.IsTransactionPending)
					{
						cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
					}
				}

				// Execute query.
				adapter.Fill(toReturn);
				return toReturn;
			}
			catch(Exception ex)
			{
				// some error occured. Bubble it to caller and encapsulate Exception object
				throw new Exception("T_Project_SalseAgency::SelectAll::Error occured.", ex);
			}
			finally
			{
				if(_mainConnectionIsCreatedLocal)
				{
					// Close connection.
					_mainConnection.Close();
				}
				cmdToExecute.Dispose();
				adapter.Dispose();
			}
		}


		#region Class Property Declarations
		public SqlGuid Project_SalseAgency_ID
		{
			get
			{
				return _project_SalseAgency_ID;
			}
			set
			{
				_project_SalseAgency_ID = value;
			}
		}


        public SqlInt32 Project_SalseAgency_TypeID
        {
            get
            {
                return _project_SalseAgency_TypeID;
            }
            set
            {
                SqlInt32 project_SalseAgency_TypeIDTmp = (SqlInt32)value;
                if (project_SalseAgency_TypeIDTmp.IsNull)
                {
                   // throw new ArgumentOutOfRangeException("Project_SalseAgency_TypeID", "Project_SalseAgency_TypeID can't be NULL");
                }
                _project_SalseAgency_TypeID = value;
            }
        }


		public SqlGuid Project_SalseAgency_MainID
		{
			get
			{
				return _project_SalseAgency_MainID;
			}
			set
			{
				SqlGuid project_SalseAgency_MainIDTmp = (SqlGuid)value;
				if(project_SalseAgency_MainIDTmp.IsNull)
				{
					//throw new ArgumentOutOfRangeException("Project_SalseAgency_MainID", "Project_SalseAgency_MainID can't be NULL");
				}
				_project_SalseAgency_MainID = value;
			}
		}


		public SqlString Project_SalseAgency_FirstA1
		{
			get
			{
				return _project_SalseAgency_FirstA1;
			}
			set
			{
				SqlString project_SalseAgency_FirstA1Tmp = (SqlString)value;
				if(project_SalseAgency_FirstA1Tmp.IsNull)
				{
					//throw new ArgumentOutOfRangeException("Project_SalseAgency_FirstA1", "Project_SalseAgency_FirstA1 can't be NULL");
				}
				_project_SalseAgency_FirstA1 = value;
			}
		}


		public SqlString Project_SalseAgency_FirstA2
		{
			get
			{
				return _project_SalseAgency_FirstA2;
			}
			set
			{
				SqlString project_SalseAgency_FirstA2Tmp = (SqlString)value;
				if(project_SalseAgency_FirstA2Tmp.IsNull)
				{
					//throw new ArgumentOutOfRangeException("Project_SalseAgency_FirstA2", "Project_SalseAgency_FirstA2 can't be NULL");
				}
				_project_SalseAgency_FirstA2 = value;
			}
		}


		public SqlString Project_SalseAgency_FirstA3
		{
			get
			{
				return _project_SalseAgency_FirstA3;
			}
			set
			{
				SqlString project_SalseAgency_FirstA3Tmp = (SqlString)value;
				if(project_SalseAgency_FirstA3Tmp.IsNull)
				{
					//throw new ArgumentOutOfRangeException("Project_SalseAgency_FirstA3", "Project_SalseAgency_FirstA3 can't be NULL");
				}
				_project_SalseAgency_FirstA3 = value;
			}
		}


		public SqlString Project_SalseAgency_FirstB1
		{
			get
			{
				return _project_SalseAgency_FirstB1;
			}
			set
			{
				SqlString project_SalseAgency_FirstB1Tmp = (SqlString)value;
				if(project_SalseAgency_FirstB1Tmp.IsNull)
				{
					//throw new ArgumentOutOfRangeException("Project_SalseAgency_FirstB1", "Project_SalseAgency_FirstB1 can't be NULL");
				}
				_project_SalseAgency_FirstB1 = value;
			}
		}


		public SqlString Project_SalseAgency_FirstB2
		{
			get
			{
				return _project_SalseAgency_FirstB2;
			}
			set
			{
				SqlString project_SalseAgency_FirstB2Tmp = (SqlString)value;
				if(project_SalseAgency_FirstB2Tmp.IsNull)
				{
					//throw new ArgumentOutOfRangeException("Project_SalseAgency_FirstB2", "Project_SalseAgency_FirstB2 can't be NULL");
				}
				_project_SalseAgency_FirstB2 = value;
			}
		}
		#endregion
	}
}
